/**
 * 场景样式工具
 */

interface Tcurrent {
  brightness?:number;
  contrast?:number;
  hue?:number;
  saturation?:number;
  gamma?:number;
  alpha?:number;
}
interface Tcorrection {
  brightness?: number;
  contrast?: number;
  hue?: number;
  saturation?: number;
}
interface TloomEffect {
  threshold?: number;
  bloomIntensity?: number;
}

class MapStyle {
  viewer: any;
  correction:any;
  constructor(viewer: any) {
    this.viewer = viewer;
  };
  /**
   * 修改场景颜色
   * brightness: 亮度
   * contrast: 对比度
   * hue: 色调
   * saturation: 饱和度
   * gamma: 伽马
   * alpha: 透明度
   */
  setImagery(current:Tcurrent) {
    // 默认的地图的透明度直接设置为 0
    this.viewer.imageryLayers.get(0).alpha = 0
    const currentLayer = this.viewer.imageryLayers.get(1);
    for(let key in current) {
      currentLayer[key] = parseFloat(current[key]);
    }
  }
  /**
   * 修改模型颜色
   * brightness: 亮度
   * contrast: 对比度
   * hue: 色调
   * saturation: 饱和度
   * gamma: 伽马
   * alpha: 透明度
   */
  setLayer(current:Tcurrent,promise:any) {
    this.viewer.imageryLayers.get(0).alpha = 0;
    Cesium.when(promise, (layers) => {
      layers.forEach((layer) => {
        for(let key in current) {
          if(key === 'alpha'){ // 当前是倾斜模型并且当前修改的是透明度选项
            layer.style3D.fillForeColor = new Cesium.Color(1.0, 1.0, 1.0, parseFloat(current[key]))
          } else {
            layer[key] = parseFloat(current[key]);
          }
        }
      })
    })
  }
  /**
   * 场景颜色设置和校正
   * brightness: 亮度
   * contrast: 对比
   * hue: 色调
   * saturation: 饱和度
   */
  setCorrection(current:Tcorrection,promise:any) {
    this.viewer.imageryLayers.get(0).alpha = 0 // 默认的地图的透明度直接设置为0
    this.correction = this.viewer.scene.colorCorrection // 创建颜色校正对象
    this.correction.show = true // 开启颜色校正

    Cesium.when(promise, () => {
      for(let key in current) {
        this.correction[key] = parseFloat(current[key]);
      }
    })
  }
  /**
   * 场景泛光设置
   * threshold 亮度 
   * bloomIntensity 强度 
   */
  setBloomEffect(current:TloomEffect,promise:any) {
    Cesium.when(promise, () => {
      for(let key in current) {
        this.viewer.scene.bloomEffect[key] = parseFloat(current[key]);
      }
    })
  }
}

export default MapStyle;